package com.xh.bussiness.tiku.controller;

import com.xh.bussiness.tiku.bean.dto.PaperChapterDto;
import com.xh.bussiness.tiku.bean.request.PaperChapterRequest;
import com.xh.bussiness.tiku.service.IPaperChapterService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *
 * </p>
 *
 * @author Pitt zhang
 * @since 2019/3/4
 */
@Api(tags="试卷章节接口")
@RestController
@RequestMapping("/tiku/paperChapter")
public class PaperChapterController  extends BaseController {

    @Autowired
    private IPaperChapterService paperChapterService;

    /**
     * 分页查询
     */
    @ApiOperation(value = "试卷章节分页查询", notes = "试卷章节分页查询")
    @PostMapping("/queryPage")
    public XhPage queryPage(XhPage page, PaperChapterRequest request) {
        return paperChapterService.queryPaperChapterPage(page,request);
    }

    /**
     * 数据查询
     * @param request
     * @return
     */
    @ApiOperation(value="试卷章节查询", notes = "试卷章节查询")
    @PostMapping("/queryAll")
    public AjaxResult queryAll(PaperChapterRequest request) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, "", paperChapterService.queryPaperChapter(request));
    }


    /**
     * 新增和保存
     * @param paperChapterDto 实体对象
     * @return
     */
    @ApiOperation(value="试卷章节保存", notes = "试卷章节保存")
    @PostMapping(value="/saveOrUpdate")
    @Transactional
    public AjaxResult saveOrUpdate(@Validated PaperChapterDto paperChapterDto){
        if(paperChapterDto.getId()==null){
            paperChapterService.insertObj(paperChapterDto);
        }else{
            paperChapterService.updateObj(paperChapterDto);
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"", paperChapterDto);
    }

    /**
     * 删除操作
     * @param id
     * @return
     */
    @ApiOperation(value="试卷章节删除", notes = "试卷章节删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id", value="试卷章节id", required = true, dataType = "String"),
    })
    @PostMapping("/deleteById")
    @Transactional
    public AjaxResult deleteById(String id){
        paperChapterService.delete(id);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }

    /**
     * 批量删除操作
     * @param ids
     * @return
     */
    @ApiOperation(value="试卷章节批量删除", notes = "试卷章节批量删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name="ids", value="试卷章节id集合", required = true, dataType = "String[]"),
    })
    @PostMapping("/batchDelete")
    @Transactional
    public AjaxResult batchDelete(String[] ids){
        paperChapterService.batchDelete(ids);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }
}
